import request from '@/utils/request'

// 查询列表
export function queryTableData() {
  return request({
    url: '/funConfig/ignore/list',
    method: 'get'
  })
}

// 修改例外无 optinos
export function getEditOptions(query:any) {
  return request({
    url: '/SYSConfig/machineType/list',
    method: 'get',
    params: query
  })
}

// 修改列表
export function editTableData(data:any) {
  return request({
    url: '/funConfig/ignore',
    method: 'put',
    data: data
  })
}

const cellRenderer = (params:any) => {
  return params.rowIndex + 1   // 用于字体垂直居中
}

const cellRendererTimeRules = ({ data }:any) => {
  return data.neglectingConditions + '秒 忽视'
}

const cellStyleStartStopStatus = ({ data }:any) => {
  if(data.startStopStatus === '关闭'){
    console.log(data)
    return {
      background: '#ffd966'
    }
  }
}

export const column = [
  {
    headerName: "机况忽视逻辑", field: "machineIgnoringLogic", minWidth: 200, flex: 1, filter: 'agMultiColumnFilter'
  },
  {
    headerName: "序号", field: "test", minWidth: 50, flex: 1, cellRenderer
  },
  {
    headerName: "时间规则", field: "timeRules", minWidth: 100, flex: 1, filter: 'agMultiColumnFilter', cellRenderer: cellRendererTimeRules
  },
  {
    headerName: "优先级", field: "priority", minWidth: 60, flex: 1, filter: 'agMultiColumnFilter'
  },
  {
    headerName: "流失条件",
    children: [
        {
          headerName: '前状态',
          children: [
            { headerName: "EPT描述", field: "beforeEptDescription", minWidth: 100, flex: 1, tooltipField:'beforeEptDescription', filter: 'agMultiColumnFilter' },
            { headerName: "R_CODE", field: "beforeEptRcode", minWidth: 100, flex: 1, tooltipField:'beforeEptRcode', filter: 'agMultiColumnFilter' }
          ]
        },
        {
          headerName: '现状态',
          children: [
            { headerName: "EPT描述", field: "nowEptDescription", minWidth: 100, flex: 1, tooltipField:'nowEptDescription', filter: 'agMultiColumnFilter' },
            { headerName: "R_CODE", field: "nowEptRcode", minWidth: 100, flex: 1, tooltipField:'nowEptRcode', filter: 'agMultiColumnFilter' }
          ]
        },
        {
          headerName: '后状态',
          children: [
            { headerName: "EPT描述", field: "afterEptDescription", minWidth: 100, flex: 1, tooltipField:'afterEptDescription', filter: 'agMultiColumnFilter' },
            { headerName: "R_CODE", field: "afterEptRcode", minWidth: 100, flex: 1, tooltipField:'afterEptRcode', filter: 'agMultiColumnFilter' }
          ]
        }
    ]
  },

  {
    headerName: "忽视处理逻辑",  children: [
        {
          headerName: '处理状态',
          field: "processingStatus", minWidth: 100, flex: 1, filter: 'agMultiColumnFilter'
        },
        {
          headerName: '忽视条件',
          field: "neglectingConditions", minWidth: 100, flex: 1, filter: 'agMultiColumnFilter'
        },
        {
          headerName: '适用对象',
          field: "applicableObjects", minWidth: 300, flex: 1, tooltipField:'applicableObjects', filter: 'agMultiColumnFilter'
        }
      ]
  },

  { headerName: "启停状态", field: "startStopStatus", minWidth: 100, flex: 1, filter: 'agMultiColumnFilter', cellStyle: cellStyleStartStopStatus },
  { headerName: "备注", field: "comments", minWidth: 300, flex: 1, tooltipField:'comments' }
]